#序列中过滤掉负数
from random import  randint  #随机数
from collections import namedtuple #元祖命名
from collections import  Counter #统计频率
import re #正则表达式
import os
# list1 = [randint(-10,10) for _ in range(10)]
# new_list1 = [x for x in list1 if x > 0]
# print('原始：',list1)
# print('转化后：',new_list1)


#筛出字典大于60的值
# dict1 = {x:randint(30,100) for x in range(1,21)}
# new_dict1 = {k:v for k,v in dict1.items() if v > 60 }
# print('原始：',dict1)
# print('转化后：',new_dict1)


#筛出集合可以被3整除的子集
# set1 = set([randint(-10,10) for _ in range(20)])
# new_dict1 = {x for x in set1 if x%3 == 0}
# print('原始：',dict1)
# print('转化后：',new_dict1)


#为元祖命名提高程序可读性
# Students = namedtuple('Students',['name','age','score'])
# s1 = Students('ming',18,95)
# s2 = Students(score=20,name='gang',age=30)
# print(s1)
# print(s2)

#随机序列出现频率最高额度三个元素
# list2 = [randint(0,20) for _ in range(30)]
# counter_list2 = Counter(list2)
# ditc_list2 = dict.fromkeys(list2,0)
# for x in list2:
#     ditc_list2[x]+=1
# ditc_list3 = dict(sorted(ditc_list2.items(),key = lambda x:x[1],reverse=True)[:3])
# print(list2)
# print(ditc_list2)
# print(ditc_list3)
# print(counter_list2.most_common(3))


#统计文章词频
# txt = open('test1.txt').read()
# c3 = Counter(re.split('\W',txt))
# print(c3)
# print(c3.most_common(10))

